from ..components import info
import pygame


# 游戏载入界面类
class LoadScreen:
    def __init__(self):
        pass

    # 将初始化方法放入start方法内，使其能够被反复调用，方便不同阶段信息共享
    # 参数game_info为各个阶段传递的关键游戏信息(时间、生命数等)
    # 每次只需更新game_info并调用start方法即可实现数据更新和传递
    def start(self, game_info):
        self.game_info = game_info
        self.finished = False  # 游戏载入界面完结标志初始化为False
        self.next = 'level'  # 下一阶段调用的关卡类名
        self.duration = 2000  # 阶段持续时长
        self.timer = 0  # 设置计时器变量timer
        self.info = info.Info('load_screen', self.game_info)  # 实例化Info类

    # 游戏载入界面更新方法
    def update(self, surface, keys):
        self.draw(surface)  # 调用载入画面绘制方法进行重绘
        # 通过比较计时器和当前系统时间变量确定是否更改完结标志和计时器变量
        if self.timer == 0:
            self.timer = pygame.time.get_ticks()
        elif pygame.time.get_ticks() - self.timer > 2000:
            self.finished = True
            self.timer = 0

    # 游戏载入界面绘制方法
    def draw(self, surface):
        surface.fill((0, 0, 0))  # 载入屏幕画面底色填充(0, 0, 0)为黑色
        self.info.draw(surface)


class GameOver(LoadScreen):

    def start(self, game_info):
        self.game_info = game_info
        self.finished = False
        self.next = 'main_menu'
        self.duration = 4000
        self.timer = 0
        self.info = info.Info('game_over', self.game_info)